package cj.web.portal.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;

/**
 * 
 * @author 
 *
 */
@DAO
public interface WatchHistoryVoDAO{
	
	@SQL("SELECT a.*,b.name as memberName,c.name as videoName,c.url as videoUrl FROM WatchHistory a left join member b on a.memberId = b.id left join video c on a.videoId =c.id WHERE a.memberId = :1 ORDER BY a.createAt DESC LIMIT :2,:3 ")
    List<Map> query(int memberId,int start,int length);
	
	@SQL("SELECT count(1) FROM WatchHistory WHERE memberId = :1 ")
    int querySize(int memberId);
	
	@SQL("SELECT count(1) FROM WatchHistory WHERE memberId =:1 AND videoId=:2 ")
    int querySize(int memberId,int videoId);
	
	@SQL("SELECT count(1) FROM WatchHistory WHERE memberId =:1 AND videoId=:2 AND status=:3 ")
    int querySize(int memberId,int videoId,int status);
	
	@SQL("SELECT * FROM (select DATE(createAt) as createAt from WatchHistory where memberId =:1 )a GROUP BY createAt ORDER BY createAt DESC LIMIT :2,:3 ")
	List<Map> getGroupTime(int memberId,int start,int length);
	
	@SQL("SELECT a.*,b.name as memberName,c.name as videoName,c.url as videoUrl,c.img FROM WatchHistory a left join member b on a.memberId = b.id left join video c on a.videoId =c.id WHERE DATE(a.createAt) = :1 AND a.memberId =:2 ")
	List<Map> getWatchHistoryByCreateAtlis(String createAt,int memberId);
	
	@SQL("INSERT INTO WatchHistory (memberId,videoId,createAt,categoryPid,status) VALUES (:1,:2,now(),:3,1) ")
    void create(int memberId,int videoId,int categoryPid);
	
	@SQL("UPDATE WatchHistory SET status=2 WHERE memberId=:1 AND videoId=:2 ")
    void updateWatchHistoryForStatus(int memberId,int videoId);
	
	@SQL("SELECT * FROM WatchHistory WHERE memberId=:1 AND videoId=:2 ")
	List<Map> queryWatchHistorylis(int memberId,int videoId);
}